﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace TimeSolve
{

    public class ColorBar : Canvas
    {
        public ColorBar()
        {
            ClipToBounds = false;
            VerticalAlignment = VerticalAlignment.Center;
            HorizontalAlignment = HorizontalAlignment.Right;
            Margin = new Thickness(0, 0, 100, 0);
            setSize(500, 20);
        }
        private int segNum;
        TextBlock[] texts;
        public void setSize(double height, double width)
        {
            this.Height = height;
            this.Width = width;
        }
        public void setColorRange( double min, double max)
        {
            double space = (max - min) / segNum;
            double hspace = this.Height / segNum;
            for (int i = 0; i <= segNum; i++)
            {
                texts[i].Text = (min + space * i).ToString("g5");
                Canvas.SetLeft(texts[i], this.Width + 5);
                Canvas.SetTop(texts[i], this.Height - 5 - hspace * i);
            }
        }
        public void setColor(Brush brush,int segNum)
        {
            this.Background = brush;
            this.segNum = segNum;
            texts = new TextBlock[segNum + 1];
            for(int i = 0; i < texts.Length; i++)
            {
                texts[i] = new TextBlock()
                {
                    Height = 20,
                };
                this.Children.Add(texts[i]);
            }
        }
    }

}




//public GraphItem GraphObject
//{
//    get { return (GraphItem)GetValue(GraphObjectProperty); }
//    set { SetValue(GraphObjectProperty, value); }
//}
//public static readonly DependencyProperty GraphObjectProperty =
//    DependencyProperty.Register("GraphObject", typeof(GraphItem), typeof(HelixGraphControl), new PropertyMetadata(null,new PropertyChangedCallback (GraphObjectChanged)));

//public static void GraphObjectChanged(DependencyObject obj,DependencyPropertyChangedEventArgs e)
//{
//    if (e == null) return;
//    HelixGraphControl hc = obj as HelixGraphControl;
//    GraphItem  graphData = e.NewValue as GraphItem;
//    hc.vhelix.Children.Clear();
//    if (graphData == null)
//    {
//        //hc.helixVisual3Ds = null;

//    }else
//    {
//        List<ModelVisual3D> ml = graphData.getVisual3Ds();
//        foreach (ModelVisual3D m in ml)
//        {
//            hc.vhelix.Children.Add(m);
//        }
//       // hc.helixVisual3Ds = graphData.helixVisual3Ds;
//    }
//}